<?php
/**
 * Created by PhpStorm.
 * User: jurentech
 * Date: 2019-10-09
 * Time: 17:25
 */

namespace app\master\controller;

class Retail extends Base
{
//    分销员列表页面
    public function index()
    {

        return $this->fetch();
    }
    public function record()
    {
        $id=input('id');
        $this->assign('id',$id);
        return $this->fetch();
    }
    public function recordlist()
    {
        $id=input('id');
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = db('user_record')
            ->where(['user_id'=>$id])
//            ->order('sort DESC')
            ->page($page['page'], $page['limit'])
            ->select();
//        var_dump($result);
        foreach ($result['data'] as $k => $v) {
            $result['data'][$k]['create_time'] = date('Y-m-d H:i:s', $result['data'][$k]['create_time']);
            $result['data'][$k]['update_time'] = date('Y-m-d H:i:s', $result['data'][$k]['update_time']);
            $result['data'][$k]['record_time'] = date('Y-m-d H:i:s', $result['data'][$k]['record_time']);
            $result['data'][$k]['openid'] =db('users')->where(['id'=>$id])->value('open_id');

//            $result['data'][$k]['name'] = db('users')->where(['id' => $result['data'][$k]['id']])->count();
//            $result['data'][$k]['phone'] = db('user')->where(['top_id' => $result['data'][$k]['id']])->count();
        }
        $result['count'] = db('user_record')->where(['user_id'=>$id])->count();
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }
    public function fenxiaoinit()
    {
        $id=input('id');
        $data['user']=db('users')->where(['id'=>$id])->find();
        $data['user']['user_time'] = date('Y-m-d H:i:s',  $data['user']['user_time']);
        $data['user']['user_ivcount'] = db('user_relation')->where(['top_id' =>  $data['user']['id']])->count();
        $data['user']['name'] = db('user_relation')->where(['top_id' =>  $data['user']['id']])->count();
        $this->assign('data',$data);
//        var_dump($data['user']);
        return $this->fetch();
    }
    public function changestatus()
    {
        $id = input('id');
        $data = db('users')->where(['id' => $id])->update(['user_type'=>0]);
        return $this->_ajax_return(200, '修改');
    }
//    分销员列表方法
    public function getlist()
    {
        $page['page'] = input("page");
        $page['limit'] = input("limit");
        $result['data'] = db('users')
            ->where(['user_type'=>1])
//            ->order('sort DESC')
            ->page($page['page'], $page['limit'])
            ->select();
//        var_dump($result);
        foreach ($result['data'] as $k => $v) {
            $result['data'][$k]['user_time'] = date('Y-m-d H:i:s', $result['data'][$k]['user_time']);
            $result['data'][$k]['user_ivcount'] = db('user_relation')->where(['top_id' => $result['data'][$k]['id']])->count();
//            $result['data'][$k]['phone'] = db('user')->where(['top_id' => $result['data'][$k]['id']])->count();
        }
        $result['count'] = db('users')->where(['user_type'=>1])->count();
        return $this->_table_return(0, "", $result['count'], $result['data']);
    }

//    分销员申请页面
    public function apply()
    {
        return $this->fetch();
    }

//    分销员申请列表方法
    public function applylist()
    {

    }
}